# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets
from gui.data_analysis.target_condition_setting import Ui_Dialog
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QDialog, QMessageBox
from utils.color_util import color
from utils.log_util import loggings as logger


class TargetConditionWindow(QtWidgets.QDialog, Ui_Dialog):
    dialogSignal = pyqtSignal(object, object, object)
    seletedSignal = pyqtSignal(object)

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        icon = QIcon()
        icon.addPixmap(
            QPixmap("icons/logo.ico"),
            QIcon.Normal,
            QIcon.Off)
        self.setWindowIcon(icon)
        self.cbb_chip_para.currentTextChanged.connect(self.select_text)

    def select_text(self, text):
        if text:
            self.seletedSignal.emit(text)

    def set_data_2_combox(self, para_list):
        self.cbb_dist_para.clear()
        self.cbb_dist_para.addItems(para_list)

    def set_chip_data_2_combox(self, para_list):
        self.cbb_chip_para.clear()
        self.cbb_chip_para.addItems(para_list)

    @pyqtSlot()
    def on_btnEnsure_clicked(self):
        try:
            target_value = self.le_correction_factor.text().strip()
            para = self.cbb_dist_para.currentText().strip()
            chip_para = self.cbb_chip_para.currentText().strip()
            if target_value and para and chip_para:
                self.dialogSignal.emit(chip_para, para, target_value)
                # self.close()
            else:
                self.show_notification("提示", "查询条件不能为空")
        except Exception as e:
            logger.error("on_btnEnsure_clicked," + str(e))

    def show_notification(self, title, content):
        QMessageBox.information(self, title, content, QMessageBox.Yes, QMessageBox.Yes)

    @pyqtSlot()
    def on_btnCancel_clicked(self):
        self.close()
